using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Amazon.S3;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using CodePlex.Resourceful.Amazon.S3.Test;
using System.Text.RegularExpressions;
using CodePlex.Resourceful.Amazon.S3.Actions;
using System.Net;

namespace CodePlex.Resourceful.Examples
{
    public static class S3Example
    {

      
        public static void Run()
        {

            string aws = Environment.GetEnvironmentVariable("AWS");

            string accessKeyID = aws.Split(':')[0];
            string secretAccessKey = aws.Split(':')[1];

            S3Connection cn = new S3Connection(accessKeyID, secretAccessKey);

            Tracer testTracer = new Tracer();
            testTracer.AddListener(Console.Out);

            S3ConnectionTests.Run(testTracer, cn, Datacenter.US);
            S3ConnectionTests.Run(testTracer, cn, Datacenter.EU);
            
        }


        // http://developer.amazonwebservices.com/connect/thread.jspa?threadID=19592
        public static void AddRemoveACL(string myAWSAccessKeyId, string mySecretAccessKeyId, string my_bucket)
        {
            // connect to s3
            S3Connection myS3 = new S3Connection(myAWSAccessKeyId, mySecretAccessKeyId);

            // grant read access to "all users"
            ACL myAcl = myS3.NewACL();
            myAcl.Add(S3Constants.Principals.AllUsers, S3Constants.Permissions.Read);
            myS3.SetACL(my_bucket, "Sunset.jpg", myAcl);

            // remove read access to "all users"
            ACL myExistingAcl = myS3.GetACL(my_bucket, "Sunset.jpg");
            myExistingAcl.Remove(S3Constants.Principals.AllUsers, S3Constants.Permissions.Read);
            myS3.SetACL(my_bucket, "Sunset.jpg", myExistingAcl);

            // or, remove all access
            myS3.SetACL(my_bucket, "Sunset.jpg", myS3.NewACL());

        }





    }
}
